<template>
  <div class="reportFormPage">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">贝克曼梁测定回弹弯沉试验检测记录表</div>
        <div class="codeText">
          <tr>
            JGLP01005a
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <div class="table-border">
        <!-- .........................1111111111111111111111111111111......................................................... -->
        <table height="220px" class="top-table">
          <tbody>
          <tr>
            <td height="30" align="center" width="15%">
              <span style="width: 90px; display: inline-block">工程名称</span>
            </td>
            <td width="35%" class="text-center">
              <span>{{ form.gongcmc }}</span>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">工程部位/用途</span>
            </td>
            <td width="35%" class="text-center">
              <span>{{ form.gongcbwyt }}</span>
            </td>
          </tr>
          <tr>
            <td height="50" align="center">样品信息</td>
            <td class="specimen-border" colspan="3">
              <span>样品名称：</span>
              <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
              <span>；样品编号：</span>
              <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
              <span>；样品数量：</span>
              <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
              <span>；样品状态：</span>
              <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
              <span>；来样时间：</span>
              <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
            </td>
          </tr>

          <tr>
            <td height="25" align="center" width="15%">
              <span style="width: 90px; display: inline-block">试验检测日期</span>
            </td>
             <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">试验条件</span>
            </td>
            <td width="35%">
              <el-input v-model="form.shiytj"/>
            </td>
          </tr>

          <tr>
            <td height="50" align="center" width="15%">
              <span style="width: 90px; display: inline-block">检测依据</span>
            </td>
            <td width="35%">
              <span v-if="isPdf">{{ form.jiancyj }}</span>
              <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark"
                        @dblclick.native="showBsJiancyjView" readonly/>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">判定依据</span>
            </td>
            <td width="35%">
              <span v-if="isPdf">{{ form.pandyj }}</span>
              <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView"
                        @focus="handleFocus('pandyj')" class="mark"/>
            </td>
          </tr>
          <tr class="bottom-border">
            <td height="50" align="center">
              <div>主要仪器设备</div>
              <div>名称及编号</div>
            </td>
            <td colspan="3">
              <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark"
                        @dblclick.native="showBsInstrumentView" readonly></el-input>
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="616px" class="middle-table">
          <tbody>
          <tr height="25">
            <td>公路等级</td>
            <td>
              <el-input  v-model="form.gongldj"/>
            </td>
            <td colspan="2">目标可靠度</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mubkkd" />
            </td>
            <td colspan="2">目标可靠指标</td>
            <td colspan="2">
              <el-input  v-model="form.mubkkzb" />
            </td>
          </tr>
          <tr height="25">
            <td>沥青面层底面处的温度</td>
            <td>
              <el-input  :type="isPdf ? 'string' : 'number'" v-model="form.liqmcdmcdwd"/>
            </td>
            <td colspan="2">路基顶面回弹模量</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.lujdmhtml" />
            </td>
            <td colspan="2">沥青结合料材料厚度</td>
            <td colspan="2">
              <el-input  v-model="form.liqjhlclhd" />
            </td>
          </tr>
          <tr height="25">
            <td>沥青结合料材料层终点温度</td>
            <td>
              <el-input  :type="isPdf ? 'string' : 'number'" v-model="form.liqjhlclczdwd"/>
            </td>
            <td colspan="2">舍弃系数</td>
            <td colspan="2">
              <el-input v-model="form.sheqxs" />
            </td>
            <td colspan="2">沥青面层厚度</td>
            <td colspan="2">
              <el-input  :type="isPdf ? 'string' : 'number'" v-model="form.liqmchd" />
            </td>
          </tr>
          <tr height="25">
            <td>湿度影响系数</td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shidyxxs" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'"/>
            </td>
            <td colspan="2">温度影响系数</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.wendyxxs" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'"/>
            </td>
            <td colspan="2">设计弯沉(0.01mm)</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shejwc" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 0, 2)" :ref="'0_2'"/>
            </td>
          </tr>
          <tr height="25">
            <td>路段桩号</td>
            <td>
              <span v-if="isPdf">{{ form.ludzh }}</span>
              <el-input v-else type="textarea" v-model="form.ludzh" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'"/>
            </td>
            <td colspan="2">弯沉仪类型</td>
            <td colspan="2">
              <span v-if="isPdf">{{ form.wancylx }}</span>
              <el-input v-else type="textarea" v-model="form.wancylx" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'"/>
            </td>
            <td colspan="2">后轴重(kN)</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.houzz" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 1, 2)" :ref="'1_2'"/>
            </td>
          </tr>
          <tr height="25">
            <td>测试车车型</td>
            <td>
              <span v-if="isPdf">{{ form.cesccx }}</span>
              <el-input v-else type="textarea" v-model="form.cesccx" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 2, 0)" :ref="'2_0'"/>
            </td>
            <td colspan="2">结构层类型</td>
            <td colspan="2">
              <span v-if="isPdf">{{ form.jiegclx }}</span>
              <el-input v-else type="textarea" v-model="form.jiegclx" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 2, 1)" :ref="'2_1'"/>
            </td>
            <td colspan="2">轮胎压强(MPa)</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.luntyq" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 2, 2)" :ref="'2_2'"/>
            </td>
          </tr>
          <tr height="25">
            <td>前五天平均气温(°C)</td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.pingjwd" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 3, 0)" :ref="'3_0'"/>
            </td>
            <td colspan="2">检验用弯沉仪最大读数(0.01mm)</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.zuidds" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 3, 1)" :ref="'3_1'"/>
            </td>
            <td colspan="2">检验用弯沉仪最终读数(0.01mm)</td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.zuizds" @blur="setWcBgDataTop()"
                        @keydown.native="handleKeyDown($event, 3, 2)" :ref="'3_2'"/>
            </td>
          </tr>
          <tr height="25">
            <td rowspan="2" width="16%">测点桩号</td>
            <td rowspan="2" width="12%">车道</td>
            <td rowspan="2">路表温度(℃)</td>
            <td rowspan="2">温度修正系数</td>
            <td colspan="3">左侧(0.01mm)</td>
            <td colspan="3">右侧(0.01mm)</td>
          </tr>
          <tr height="25">
            <td>初读数</td>
            <td>终读数</td>
            <td>回弹弯沉</td>
            <td>初读数</td>
            <td>终读数</td>
            <td>回弹弯沉</td>
          </tr>
          <tr v-for="(item, index) in form.detailList" :key="index">
            <td height="25">
              <span v-if="isPdf">{{ form.cedzh }}</span>
              <el-input v-else v-model="item.cedzh" :row="2" @blur="setReportData()"
                        @keydown.native="handleKeyDown($event, index + 4, 0)" :ref="`${index + 4}_0`"/>
            </td>
            <td>
              <span v-if="isPdf">{{ form.ched }}</span>
              <el-input v-else v-model="item.ched" :row="2" @blur="setReportData()"
                        @keydown.native="handleKeyDown($event, index + 4, 1)" :ref="`${index + 4}_1`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.lubwd" @blur="setReportData()"
                        @keydown.native="handleKeyDown($event, index + 4, 2)" :ref="`${index + 4}_2`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.wendxzxs"
                        @keydown.native="handleKeyDown($event, index + 4, 3)" :ref="`${index + 4}_3`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.zuoccds"
                        @blur="calculateZuochtwc(index, 'zuoc')" @keydown.native="handleKeyDown($event, index + 4, 4)"
                        :ref="`${index + 4}_4`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.zuoczds"
                        @blur="calculateZuochtwc(index, 'zuoc')" @keydown.native="handleKeyDown($event, index + 4, 5)"
                        :ref="`${index + 4}_5`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.zuochtwc" disabled/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.youccds"
                        @blur="calculateZuochtwc(index, 'youc')" @keydown.native="handleKeyDown($event, index + 4, 6)"
                        :ref="`${index + 4}_6`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.youczds"
                        @blur="calculateZuochtwc(index, 'youc')" @keydown.native="handleKeyDown($event, index + 4, 7)"
                        :ref="`${index + 4}_7`"/>
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" v-model="item.youchtwc" disabled/>
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="60px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')"/>
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
        <tr>
          <td width="10%" align="right">检测：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">记录：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">复核：</td>
          <td align="left" width="15%"></td>
          <td width="10%">日期：</td>
          <td align="left" width="15%">
            <div style="display: inline-block; margin-left: 20px">年</div>
            <div style="display: inline-block; margin-left: 20px">月</div>
            <div style="display: inline-block ;margin-left: 20px">日</div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import {
  listWcjlbBsInfo,
  getWcjlbBsInfo,
  delWcjlbBsInfo,
  addWcjlbBsInfo,
  updateWcjlbBsInfo
} from "@/api/report_ljlm/wcjlbBsInfo";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BaQjDetailView from "@/views/sycs/baQjDetail/BaQjDetailView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";

import decimal from "@/utils/big-decimal";
import {handleFocus, emptyConvert, handleKeyDown} from "@/views/reportForms/utils";
import Bus from "@/utils/bus";

export default {
  name: "wcjlb",
  components: {
    BsInstrumentView,
    BaQjDetailView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      params: {},
      query: {},
      // 表单参数
      form: {
        detailList: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
      }
    };
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = {...emptyConvert(this.form, newVal)};
    }
  },
  created() {
    this.getInfo();
  },
  mounted() {
    // 获取顶部数据
    Bus.$on("setWcBgDataTop", (data) => {
      for (const key in data) {
        if (Object.prototype.hasOwnProperty.call(data, key)) {
          this.form[key] = data[key];
        }
      }
    });
  },
  beforeDestroy() {
    Bus.$off("setWcBgDataTop");
  },

  methods: {
    // 获取详情
    getInfo() {
      getWcjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setWcBgJiancyj", {jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds});
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setWcBgZhuyyqsbmcjbh", {zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds});
    },
    // 计算左侧回弹弯沉
    calculateZuochtwc(index, type) {
      // C=2*(A-B)
      const A = this.form.detailList[index][type + "cds"];
      const B = this.form.detailList[index][type + "zds"];
      let C = null;
      if (A && B) {
        C = decimal.multiply(2, decimal.subtract(A, B));
      }
      this.form.detailList[index][type + "htwc"] = C;
      this.setReportData();
    },
    // 给报告传值
    setReportData() {
      Bus.$emit("setWcBgData" + this.page, this.form.detailList);
    },
    setWcBgDataTop() {
      const info = {
        shidyxxs: this.form.shidyxxs,
        wendyxxs: this.form.wendyxxs,
        shejwc: this.form.shejwc,
        ludzh: this.form.ludzh,
        wancylx: this.form.wancylx,
        houzz: this.form.houzz,
        cesccx: this.form.cesccx,
        jiegclx: this.form.jiegclx,
        luntyq: this.form.luntyq,
        pingjwd: this.form.pingjwd,
        zuidds: this.form.zuidds,
        zuizds: this.form.zuizds
      };
      Bus.$emit("setWcBgDataTop", info);
    },
    submitForm() {
      return this.form;
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [2, 2, 2, 2, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]?.length) {
        this.$refs[ref][0].focus();
      } else if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped></style>
